//
//  PopForgetPsdView.m
//  HuaRun2
//
//  Created by admin on 2017/9/22.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "PopForgetPsdView.h"
#import "LineView.h"
#import "TLAttributedLabel.h"

@interface PopForgetPsdView () <UIGestureRecognizerDelegate>
@property (nonatomic, strong)UIView * backView;
//取消按钮
@property (nonatomic, strong)UIButton * cancelBtn;
//线1
@property (nonatomic, strong) LineView * line1;
//value1
@property (nonatomic, strong) UILabel * infoLab;

@property (nonatomic, strong) UILabel * waibuLab;

//确定按钮
@property(nonatomic, strong) UIButton * submitBtn;

@end

@implementation PopForgetPsdView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
#pragma mark - life cycle
    - (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
    }
    
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self viewInit];
        [self layoutInit];
    }
    return self;
}
    
- (void)viewInit {
    self.backgroundColor = RGBA(76, 76, 76, 0.8);
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissSelfMethod)];
    tap.delegate = self;
    [self addGestureRecognizer:tap];
    
    self.backView = [[UIView alloc] init];
    _backView.backgroundColor = [UIColor whiteColor];
    _backView.layer.cornerRadius = 10;
    _backView.layer.masksToBounds = YES;
    [self addSubview:self.backView];
    
    [self.backView addSubview:self.cancelBtn];

    [self.backView addSubview:self.infoLab];
    [self.backView addSubview:self.line1];
    
    [self.backView addSubview:self.waibuLab];
    [self.backView addSubview:self.waibuLabEmail];

    [self.backView addSubview:self.neibuLab];
    
    [self.backView addSubview:self.submitBtn];
}

- (void)layoutInit {
    
    weakself(ws);
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(ws);
//        make.left.mas_equalTo(ws).offset(3 * kMargin10);
//        make.right.mas_equalTo(ws).offset(-3 * kMargin10);
        make.width.mas_equalTo(ws).multipliedBy(0.64);
        make.height.mas_equalTo(ws.backView.mas_width).multipliedBy(0.76);
    }];
        
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(ws.backView.mas_right).offset(-kMargin10);
        make.top.mas_equalTo(ws.backView).offset(kMargin10);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];

    [self.infoLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView).offset(kMargin15);
        make.centerY.mas_equalTo(ws.cancelBtn);
        make.size.mas_equalTo(CGSizeMake(100, 20));
    }];

    [self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.width.mas_equalTo(ws.backView);
        make.height.mas_equalTo(1);
        make.top.mas_equalTo(ws.cancelBtn.mas_bottom).offset(kMargin10);
    }];

    [self.waibuLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.infoLab);
        make.top.mas_equalTo(ws.line1).offset(kMargin10);
        make.right.mas_equalTo(ws.cancelBtn);
    }];
    
    [self.waibuLabEmail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(ws.waibuLab);
        make.top.mas_equalTo(ws.waibuLab.mas_bottom).offset(kMargin10);
    }];

    [self.neibuLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(ws.waibuLab);
        make.top.mas_equalTo(ws.waibuLabEmail.mas_bottom).offset(2 * kMargin10);
    }];

    [self.submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.width.centerX.mas_equalTo(ws.backView);
        make.height.mas_equalTo(40);
    }];
}

- (void)dismissSelfMethod {
    
    weakself(ws);
    
    [UIView animateWithDuration:0.3 animations:^{
 
    } completion:^(BOOL finished) {
        
        [ws.backView removeFromSuperview];
        [ws removeFromSuperview];
    }];
    
}
    //是否允许响应手势
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    //    当点击backview时不响应手势
    if ([touch.view isDescendantOfView:self.backView]) {
        return NO;
    }
    
    return YES;
    
}
    
    
- (UIButton *)cancelBtn{
    if (!_cancelBtn) {
        self.cancelBtn = [UIButton new];
        [_cancelBtn setBackgroundImage:[UIImage imageNamed:@"X"]
                              forState:(UIControlStateNormal)];
        [_cancelBtn addTarget:self action:@selector(dismissSelfMethod) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _cancelBtn;
}

- (LineView *)line1 {
    if (!_line1) {
        self.line1 = [LineView new];
    }
    return _line1;
}

- (UILabel *)infoLab {
    if (!_infoLab) {
        self.infoLab = [UILabel new];
        _infoLab.textAlignment = NSTextAlignmentLeft;
        _infoLab.font = [UIFont boldSystemFontOfSize:17];
        _infoLab.textColor = [UIColor blackColor];
        _infoLab.text = NSLocalizedString(@"tips", nil);
    }
    return _infoLab;
}

- (UILabel *)waibuLab {
    if (!_waibuLab) {
        self.waibuLab = [UILabel new];
        _waibuLab.textAlignment = NSTextAlignmentLeft;
        _waibuLab.font = kGeneralFontSize;
        _waibuLab.textColor = [UIColor grayColor];
        _waibuLab.text = NSLocalizedString(@"waibu_title", nil);
        _waibuLab.numberOfLines = 0;
    }
    return _waibuLab;
}

- (UILabel *)neibuLab {
    if (!_neibuLab) {
        self.neibuLab = [UILabel new];
        _neibuLab.textAlignment = NSTextAlignmentLeft;
        _neibuLab.font = kGeneralFontSize;
        _neibuLab.numberOfLines = 0;
//        
//        "neibu_title" = "内部人员请";
//        "neibu_content" = "点击这里";
        NSMutableAttributedString *content =  [[NSMutableAttributedString alloc]initWithString:
                                               [NSString stringWithFormat:@"%@%@",
                                               NSLocalizedString(@"neibu_title", nil),
                                               NSLocalizedString(@"neibu_content", nil)]];

        NSRange contentRange1 = {0, [NSLocalizedString(@"neibu_title", nil) length]};

        NSRange contentRange = {[NSLocalizedString(@"neibu_title", nil) length],
                                 [NSLocalizedString(@"neibu_content", nil) length]};
        [content addAttribute:NSForegroundColorAttributeName
                        value:[UIColor grayColor]
                        range:contentRange1];
        [content addAttribute:NSUnderlineStyleAttributeName
                        value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
                        range:contentRange];
        [content addAttribute:NSForegroundColorAttributeName
                        value:[UIColor orangeColor]
                        range:contentRange];
        [content addAttribute:NSUnderlineColorAttributeName
                        value:[UIColor orangeColor]
                        range:contentRange];
        _neibuLab.attributedText = content;

    }
    return _neibuLab;
}

- (UILabel *)waibuLabEmail {
    if (!_waibuLabEmail) {
        self.waibuLabEmail = [UILabel new];
        _waibuLabEmail.textAlignment = NSTextAlignmentLeft;
        _waibuLabEmail.font = kGeneralFontSize;
        _waibuLabEmail.numberOfLines = 0;
        // 下划线
        //注意: NSStrikethroughStyleAttributeName 是添加中划线,这时textStr如果是中文字符则没有效果
        NSDictionary *attribtDic = @{
                                     NSUnderlineStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle],
                                     NSUnderlineColorAttributeName : [UIColor orangeColor],
                                     NSForegroundColorAttributeName: [UIColor orangeColor]};
        NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:NSLocalizedString(@"waibu_content", nil)
                                                                                                                   attributes:attribtDic];
        _waibuLabEmail.attributedText =attribtStr;
    }
    return _waibuLabEmail;
}
- (UIButton *)submitBtn {
    if (!_submitBtn) {
        self.submitBtn = [UIButton new];
        _submitBtn.backgroundColor = RGBA(243, 161, 50, 1);
        [_submitBtn setTitle:NSLocalizedString(@"confirm", nil)
                    forState:(UIControlStateNormal)];
        _submitBtn.layer.cornerRadius = 5;
        _submitBtn.layer.masksToBounds = YES;
        [_submitBtn addTarget:self action:@selector(dismissSelfMethod) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _submitBtn;
}
@end
